

export const parseFileName = (filename?: string) => {
  filename = typeof filename == 'string' ? filename : ''
  const lastDotIndex = filename.lastIndexOf('.');
  return { 
    name: lastDotIndex > -1 ? filename.slice(0, lastDotIndex) : filename,
    suffix: lastDotIndex > -1 ? filename.slice(lastDotIndex + 1) : ''
  };
}

export const getFileNameFromUrl = (url?: string) => {
  url = typeof url == 'string' ? url : ''
  const regex = /\/([^\/?#]+)(?:[?#]|$)/;
  const match = url.match(regex);
  const fullFileName =  match ? match[1] : '';
  return parseFileName(fullFileName)
}